# -*- encoding:utf-8 -*-
from mako import runtime, filters, cache
UNDEFINED = runtime.UNDEFINED
__M_dict_builtin = dict
__M_locals_builtin = locals
_magic_number = 5
_modified_time = 1291712288.66714
_template_filename=u'/Users/joeldunham/old/onlinelinguisticdatabase/templates/base/markup.html'
_template_uri=u'/base/markup.html'
_template_cache=cache.Cache(__name__, _modified_time)
_source_encoding='utf-8'
from webhelpers.html import escape
_exports = ['linkToOLDImageFiles', 'linkToOLDFiles', 'embedCollectionContent', 'linkToOLDEntitites']


# SOURCE LINE 1
import re 

def render_body(context,**pageargs):
    context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        __M_writer = context.writer()
        __M_writer(u'\n\n')
        # SOURCE LINE 5
        __M_writer(u'\n\n\n')
        # SOURCE LINE 23
        __M_writer(u'\n\n\n')
        # SOURCE LINE 31
        __M_writer(u'\n\n\n')
        # SOURCE LINE 47
        __M_writer(u'\n\n\n')
        # SOURCE LINE 65
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_linkToOLDImageFiles(context,input):
    context.caller_stack._push_frame()
    try:
        url = context.get('url', UNDEFINED)
        h = context.get('h', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 34
        __M_writer(u'\n    ')
        # SOURCE LINE 35

        patt = re.compile('(image\(([0-9a-zA-Z_ -]+.[a-zA-Z0-9]+)\))')
        matches = patt.findall(input)
        for match in matches:
            controller = 'file'
            action = 'retrieve'
            path = match[1] 
            URL = url(controller=controller, action=action, path=path)
            img = "<img class='userEmbeddedImage' src='%s' />" % URL
            input = input.replace(match[0], img)
            
        
        # SOURCE LINE 45
        __M_writer(u'\n    ')
        # SOURCE LINE 46
        __M_writer(escape(h.literal(input)))
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_linkToOLDFiles(context,input):
    context.caller_stack._push_frame()
    try:
        url = context.get('url', UNDEFINED)
        h = context.get('h', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 50
        __M_writer(u'\n    ')
        # SOURCE LINE 51

        patt = re.compile('(\[(.+)\]link\(([0-9a-zA-Z_ -]+.[a-zA-Z0-9]+)\))')
        matches = patt.findall(input)
        for match in matches:
            controller = 'file'
            action = 'retrieve'
            linkText = match[1]
            path = match[2] 
            URL = url(controller=controller, action=action, path=path)
            title = "Link to %s" % path
            a = "<a href='%s' title='%s' />%s</a>" % (URL, title, linkText)
            input = input.replace(match[0], a)
            
        
        # SOURCE LINE 63
        __M_writer(u'\n    ')
        # SOURCE LINE 64
        __M_writer(escape(h.literal(input)))
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_embedCollectionContent(context,input):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 26
        __M_writer(u'\n    ')
        # SOURCE LINE 27

        patt = re.compile('(collection\[([0-9]+)\])')
        matches = patt.findall(input)
            
        
        # SOURCE LINE 30
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_linkToOLDEntitites(context,input):
    context.caller_stack._push_frame()
    try:
        url = context.get('url', UNDEFINED)
        h = context.get('h', UNDEFINED)
        str = context.get('str', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 8
        __M_writer(u'\n    ')
        # SOURCE LINE 9

        patt = re.compile('((form|file|collection|speaker|user)\(([0-9]+)\))')
        matches = patt.findall(input)
        for match in matches:
            id = match[2]
            controller = match[1]
            if controller == 'user':
                controller = 'researcher'
            URL = url(controller=controller, action='view', id=id)
            title = 'Click to view %s %s' % (controller.capitalize(), str(id))
            anchor = "<a href='%s' title='%s'>%s %s</a>" % (URL, title, controller.capitalize(), str(id))
            input = input.replace(match[0], anchor)
            
        
        # SOURCE LINE 21
        __M_writer(u'\n    ')
        # SOURCE LINE 22
        __M_writer(escape(h.literal(input)))
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


